define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mbti/evaluate/index' + location.search,
                    edit_url: 'mbti/evaluate/edit',
                    del_url: 'mbti/evaluate/del',
                    multi_url: 'mbti/evaluate/multi',
                    import_url: 'mbti/evaluate/import',
                    table: 'mbti_evaluate',
                }
            });

            Table.button = {
                edit: {
                    name: 'edit',
                    icon: 'fa fa-pencil',
                    title: __('Edit'),
                    extend: 'data-toggle="tooltip" data-container="body" data-area=["80%","80%"]',//调整弹窗尺寸
                    classname: 'btn btn-xs btn-success btn-editone'
                },
                del: {
                    name: 'del',
                    icon: 'fa fa-trash',
                    title: __('Del'),
                    extend: 'data-toggle="tooltip" data-container="body"',
                    classname: 'btn btn-xs btn-danger btn-delone'
                },
                dragsort: {
                    name: 'dragsort',
                    icon: 'fa fa-arrows',
                    title: __('Drag to sort'),
                    extend: 'data-toggle="tooltip"',
                    classname: 'btn btn-xs btn-primary btn-dragsort'
                }
            };

            var table = $("#table");
            $(document).on("click", "#resetFromSearch", function () {
                $(".form-commonsearch [type=reset]").trigger("click");
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'mbti_ie', title: __('Mbti_value'), operate: false, formatter: Controller.api.formatter.mbti},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'applet_id', title: __('Applet_id'), operate: 'LIKE'},
                        {field: 'view_status', title: __('View_status'), searchList: {"create":__('Create'),"read":__('Read')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    text: __('Mbti Answer'),
                                    title: __('Mbti Answer'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-folder-o',
                                    extend: 'data-area=["80%","80%"]',//调整弹窗尺寸这里只能按这种格式写
                                    url: 'mbti/evaluate/answer_list'
                                },
                                {
                                    name: 'addtabs',
                                    text: __('Mbti Result'),
                                    title: __('Mbti Result'),
                                    classname: 'btn btn-xs btn-warning btn-dialog',
                                    icon: 'fa fa-folder-o',
                                    url: 'mbti/evaluate/mbti_result'
                                }
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        answer_list: function () {},
        mbti_result: function () {},
        api: {
            formatter:{
                mbti: function (value, row, index) {
                    return `${value}${row.mbti_sn}${row.mbti_tf}${row.mbti_pj}`
                }
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
